﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................

namespace QLKTX1._0.DAO
{
    class SoGiuongDAO
    {
        public static List<SoGiuongDTO> dsSoGiuong()
        {
            List<SoGiuongDTO> dsSoGiuong = new List<SoGiuongDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM SoGiuong");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                SoGiuongDTO soGiuong = new SoGiuongDTO();

                soGiuong.MaSG  = dt.Rows[i]["maSG"].ToString();
                soGiuong .SoLuong  = Int32.Parse (dt.Rows[i]["soLuong"].ToString());
                
                dsSoGiuong.Add(soGiuong);
             
            }
            return dsSoGiuong;
        }
        //ham Insert
        public static bool themSoGiuong(SoGiuongDTO soGiuong)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO SoGiuong(maSG,soLuong) VALUES('" + soGiuong.MaSG + "'," + soGiuong.SoLuong + ")");

        }
        //Ham delete
        public static bool xoaSoGiuong(SoGiuongDTO soGiuong)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("DELETE FROM SoGiuong WHERE maSG='" + soGiuong.MaSG + "'");

        }
        //Ham update
        public static bool capNhatSoGiuong(SoGiuongDTO soGiuong)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("UPDATE SoGiuong set soLuong='" + soGiuong.SoLuong + "' WHERE maSG='" + soGiuong.MaSG + "'");

        }
    }
}
